package org.gczl.core.until;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import net.sf.json.JSONObject;


/**
 * 根据appid，appSecret,code,grant_type,来获取openid和sessionKey
 * 
 * code 通过微信自己的api获取
 * appid，appSecret 微信公众平台有
 * grant_type 授权类型，此处只需填写 authorization_code
 * @author ljh
 *
 */
public class code2Session {

	
	
	public static final String appid="wxc27a20949311ca46";
	
	public static final String appSecret="a24c4b4ac725985c272ea3fbe3e6b2a7";
	
	public static final String grant_type = "authorization_code";
	
	public static JSONObject getOpenId(String code){
		
		String url = "https://api.weixin.qq.com/sns/jscode2session?"
				+ "appid="+appid+"&"
				+ "secret="+appSecret+"&"
				+ "js_code="+code+"&"
				+ "grant_type="+grant_type+"";
		
		
		String result = HttpUtil.doGet(url);
		
		JSONObject jsonObject = JSONObject.fromObject(result);
		
		return jsonObject;
		
	}
	
}
